﻿using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;

namespace KDS.Mes.Authorization
{
    public class MesAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            ////Common permissions
            //var pages = context.GetPermissionOrNull(AppPermissions.Pages);
            //if (pages == null)
            //{
            //    pages = context.CreatePermission(AppPermissions.Pages, L("Pages"));
            //}

            //var users = pages.CreateChildPermission(AppPermissions.Pages_Administration_Users, L("Users"));
            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));

            var administration = pages.CreateChildPermission(AppPermissions.Pages_Administration, L("Administration"));
            var basic= pages.CreateChildPermission(AppPermissions.Pages_Basic, L("Basic"));
            var bom = pages.CreateChildPermission(AppPermissions.Pages_Bom, L("Bom"));
            var plan = pages.CreateChildPermission(AppPermissions.Pages_Plan, L("Plan"));
            var report = pages.CreateChildPermission(AppPermissions.Pages_Report, L("Report"));

            var roles = administration.CreateChildPermission(AppPermissions.Pages_Administration_Roles, L("Roles"));
            roles.CreateChildPermission(AppPermissions.Pages_Administration_Roles_Create, L("CreatingNewRole"));
            roles.CreateChildPermission(AppPermissions.Pages_Administration_Roles_Edit, L("EditingRole"));
            roles.CreateChildPermission(AppPermissions.Pages_Administration_Roles_Delete, L("DeletingRole"));

            var users = administration.CreateChildPermission(AppPermissions.Pages_Administration_Users, L("Users"));
            users.CreateChildPermission(AppPermissions.Pages_Administration_Users_Create, L("CreatingNewUser"));
            users.CreateChildPermission(AppPermissions.Pages_Administration_Users_Edit, L("EditingUser"));
            users.CreateChildPermission(AppPermissions.Pages_Administration_Users_Delete, L("DeletingUser"));

            var factorys = basic.CreateChildPermission(AppPermissions.Pages_Basic_Factorys, L("Factorys"));
            factorys.CreateChildPermission(AppPermissions.Pages_Basic_Factorys_Create, L("CreatingNewFactory"));
            factorys.CreateChildPermission(AppPermissions.Pages_Basic_Factorys_Edit, L("EditingFactory"));
            factorys.CreateChildPermission(AppPermissions.Pages_Basic_Factorys_Delete, L("DeletingFactory"));

            var workshops = basic.CreateChildPermission(AppPermissions.Pages_Basic_Workshops, L("Workshops"));
            workshops.CreateChildPermission(AppPermissions.Pages_Basic_Workshops_Create, L("CreatingNewWorkshop"));
            workshops.CreateChildPermission(AppPermissions.Pages_Basic_Workshops_Edit, L("EditingWorkshop"));
            workshops.CreateChildPermission(AppPermissions.Pages_Basic_Workshops_Delete, L("DeletingWorkshop"));

            var lines = basic.CreateChildPermission(AppPermissions.Pages_Basic_Lines, L("Lines"));
            lines.CreateChildPermission(AppPermissions.Pages_Basic_Lines_Create, L("CreatingNewLine"));
            lines.CreateChildPermission(AppPermissions.Pages_Basic_Lines_Edit, L("EditingLine"));
            lines.CreateChildPermission(AppPermissions.Pages_Basic_Lines_Delete, L("DeletingLine"));

            var stations = basic.CreateChildPermission(AppPermissions.Pages_Basic_Stations, L("Stations"));
            stations.CreateChildPermission(AppPermissions.Pages_Basic_Stations_Create, L("CreatingNewStation"));
            stations.CreateChildPermission(AppPermissions.Pages_Basic_Stations_Edit, L("EditingStation"));
            stations.CreateChildPermission(AppPermissions.Pages_Basic_Stations_Delete, L("DeletingStation"));

            var storages = basic.CreateChildPermission(AppPermissions.Pages_Basic_Storages, L("Storages"));
            storages.CreateChildPermission(AppPermissions.Pages_Basic_Storages_Create, L("CreatingNewStorage"));
            storages.CreateChildPermission(AppPermissions.Pages_Basic_Storages_Edit, L("EditingStorage"));
            storages.CreateChildPermission(AppPermissions.Pages_Basic_Storages_Delete, L("DeletingStorage"));


            var cartypes = bom.CreateChildPermission(AppPermissions.Pages_Bom_Cartypes, L("Cartypes"));
            cartypes.CreateChildPermission(AppPermissions.Pages_Bom_Cartypes_Create, L("CreatingNewCartype"));
            cartypes.CreateChildPermission(AppPermissions.Pages_Bom_Cartypes_Edit, L("EditingCartype"));
            cartypes.CreateChildPermission(AppPermissions.Pages_Bom_Cartypes_Delete, L("DeletingCartype"));

            var alcs = bom.CreateChildPermission(AppPermissions.Pages_Bom_Alcs, L("Alcs"));
            alcs.CreateChildPermission(AppPermissions.Pages_Bom_Alcs_Create, L("CreatingNewAlc"));
            alcs.CreateChildPermission(AppPermissions.Pages_Bom_Alcs_Edit, L("EditingAlc"));
            alcs.CreateChildPermission(AppPermissions.Pages_Bom_Alcs_Delete, L("DeletingAlc"));

            var styles = bom.CreateChildPermission(AppPermissions.Pages_Bom_Styles, L("Styles"));
            styles.CreateChildPermission(AppPermissions.Pages_Bom_Styles_Create, L("CreatingNewStyle"));
            styles.CreateChildPermission(AppPermissions.Pages_Bom_Styles_Edit, L("EditingStyle"));
            styles.CreateChildPermission(AppPermissions.Pages_Bom_Styles_Delete, L("DeletingStyle"));

            var alccodes = bom.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodes, L("AlcCodes"));
            alccodes.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodes_Create, L("CreatingNewAlcCode"));
            alccodes.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodes_Edit, L("EditingAlcCode"));
            alccodes.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodes_Delete, L("DeletingAlcCode"));

            var seatpositions = bom.CreateChildPermission(AppPermissions.Pages_Bom_SeatPositions, L("SeatPositions"));
            seatpositions.CreateChildPermission(AppPermissions.Pages_Bom_SeatPositions_Create, L("CreatingNewSeatPosition"));
            seatpositions.CreateChildPermission(AppPermissions.Pages_Bom_SeatPositions_Edit, L("EditingSeatPosition"));
            seatpositions.CreateChildPermission(AppPermissions.Pages_Bom_SeatPositions_Delete, L("DeletingSeatPosition"));

            var colors = bom.CreateChildPermission(AppPermissions.Pages_Bom_Colors, L("Colors"));
            colors.CreateChildPermission(AppPermissions.Pages_Bom_Colors_Create, L("CreatingNewColor"));
            colors.CreateChildPermission(AppPermissions.Pages_Bom_Colors_Edit, L("EditingColor"));
            colors.CreateChildPermission(AppPermissions.Pages_Bom_Colors_Delete, L("DeletingColor"));

            var materials = bom.CreateChildPermission(AppPermissions.Pages_Bom_Materials, L("Materials"));
            materials.CreateChildPermission(AppPermissions.Pages_Bom_Materials_Create, L("CreatingNewMaterial"));
            materials.CreateChildPermission(AppPermissions.Pages_Bom_Materials_Edit, L("EditingMaterial"));
            materials.CreateChildPermission(AppPermissions.Pages_Bom_Materials_Delete, L("DeletingMaterial"));

            var parts = bom.CreateChildPermission(AppPermissions.Pages_Bom_Parts, L("Parts"));
            parts.CreateChildPermission(AppPermissions.Pages_Bom_Parts_Create, L("CreatingNewPart"));
            parts.CreateChildPermission(AppPermissions.Pages_Bom_Parts_Edit, L("EditingPart"));
            parts.CreateChildPermission(AppPermissions.Pages_Bom_Parts_Delete, L("DeletingPart"));

            var seatInfos = bom.CreateChildPermission(AppPermissions.Pages_Bom_SeatInfos, L("SeatInfos"));
            seatInfos.CreateChildPermission(AppPermissions.Pages_Bom_SeatInfos_Create, L("CreatingNewSeatInfo"));
            seatInfos.CreateChildPermission(AppPermissions.Pages_Bom_SeatInfos_Edit, L("EditingSeatInfo"));
            seatInfos.CreateChildPermission(AppPermissions.Pages_Bom_SeatInfos_Delete, L("DeletingSeatInfo"));

            var productModes = bom.CreateChildPermission(AppPermissions.Pages_Bom_ProductModes, L("ProductModes"));
            productModes.CreateChildPermission(AppPermissions.Pages_Bom_ProductModes_Create, L("CreatingNewProductMode"));
            productModes.CreateChildPermission(AppPermissions.Pages_Bom_ProductModes_Edit, L("EditingProductMode"));
            productModes.CreateChildPermission(AppPermissions.Pages_Bom_ProductModes_Delete, L("DeletingProductMode"));

            //var lineAlcCodes = bom.CreateChildPermission(AppPermissions.Pages_Bom_LineAlcCodes, L("LineAlcCodes"));
            //lineAlcCodes.CreateChildPermission(AppPermissions.Pages_Bom_LineAlcCodes_Create, L("CreatingNewLineAlcCode"));
            //lineAlcCodes.CreateChildPermission(AppPermissions.Pages_Bom_LineAlcCodes_Edit, L("EditingLineAlcCode"));
            //lineAlcCodes.CreateChildPermission(AppPermissions.Pages_Bom_LineAlcCodes_Delete, L("DeletingLineAlcCode"));

            var psrocessType = bom.CreateChildPermission(AppPermissions.Pages_Bom_ProcessTypes, L("ProcessTypes"));
            psrocessType.CreateChildPermission(AppPermissions.Pages_Bom_ProcessTypes_Create, L("CreatingNewProcessType"));
            psrocessType.CreateChildPermission(AppPermissions.Pages_Bom_ProcessTypes_Edit, L("EditingProcessType"));
            psrocessType.CreateChildPermission(AppPermissions.Pages_Bom_ProcessTypes_Delete, L("DeletingProcessType"));

            var jitAlcCode = bom.CreateChildPermission(AppPermissions.Pages_Bom_JitAlcCodes, L("JitAlcCodes"));
            jitAlcCode.CreateChildPermission(AppPermissions.Pages_Bom_JitAlcCodes_Create, L("CreatingNewJitAlcCode"));
            jitAlcCode.CreateChildPermission(AppPermissions.Pages_Bom_JitAlcCodes_Edit, L("EditingJitAlcCode"));
            jitAlcCode.CreateChildPermission(AppPermissions.Pages_Bom_JitAlcCodes_Delete, L("DeletingJitAlcCode"));


            var planModes = plan.CreateChildPermission(AppPermissions.Pages_Plan_PlanModes, L("PlanModes"));
            planModes.CreateChildPermission(AppPermissions.Pages_Plan_PlanModes_Create, L("CreatingNewPlanMode"));
            planModes.CreateChildPermission(AppPermissions.Pages_Plan_PlanModes_Edit, L("EditingPlanMode"));
            planModes.CreateChildPermission(AppPermissions.Pages_Plan_PlanModes_Delete, L("DeletingPlanMode"));

            var _plan = plan.CreateChildPermission(AppPermissions.Pages_Plan_Plans, L("Plans"));
            _plan.CreateChildPermission(AppPermissions.Pages_Plan_Plans_Create, L("CreatingNewPlan"));
            _plan.CreateChildPermission(AppPermissions.Pages_Plan_Plans_Edit, L("EditingPlan"));
            _plan.CreateChildPermission(AppPermissions.Pages_Plan_Plans_Delete, L("DeletingPlan"));

            var planDetails = plan.CreateChildPermission(AppPermissions.Pages_Plan_PlanDetails, L("PlanDetails"));
            planDetails.CreateChildPermission(AppPermissions.Pages_Plan_PlanDetails_Create, L("CreatingNewPlanDetail"));
            planDetails.CreateChildPermission(AppPermissions.Pages_Plan_PlanDetails_Edit, L("EditingPlanDetail"));
            planDetails.CreateChildPermission(AppPermissions.Pages_Plan_PlanDetails_Delete, L("DeletingPlanDetail"));

            var onlines = plan.CreateChildPermission(AppPermissions.Pages_Plan_Onlines, L("Onlines"));
            onlines.CreateChildPermission(AppPermissions.Pages_Plan_Onlines_Create, L("CreatingNewOnline"));
            onlines.CreateChildPermission(AppPermissions.Pages_Plan_Onlines_Edit, L("EditingOnline"));
            onlines.CreateChildPermission(AppPermissions.Pages_Plan_Onlines_Delete, L("DeletingOnline"));

            var seqJits = plan.CreateChildPermission(AppPermissions.Pages_Plan_SeqJits, L("SeqJits"));
            seqJits.CreateChildPermission(AppPermissions.Pages_Plan_SeqJits_Create, L("CreatingNewSeqJit"));
            seqJits.CreateChildPermission(AppPermissions.Pages_Plan_SeqJits_Edit, L("EditingSeqJit"));
            seqJits.CreateChildPermission(AppPermissions.Pages_Plan_SeqJits_Delete, L("DeletingSeqJit"));



            var testSlides = report.CreateChildPermission(AppPermissions.Pages_Report_TestSlides, L("TestSlides"));
            var testPower2s = report.CreateChildPermission(AppPermissions.Pages_Report_TestPower2s, L("TestPower2s"));
            var testImss = report.CreateChildPermission(AppPermissions.Pages_Report_TestImss, L("TestImss"));
            var testRlifts = report.CreateChildPermission(AppPermissions.Pages_Report_TestRlifts, L("TestRlifts"));
            var atlas = report.CreateChildPermission(AppPermissions.Pages_Report_Atlass, L("Atlass"));
            var atlasCpk = report.CreateChildPermission(AppPermissions.Pages_Report_AtlasCpks, L("AtlasCpks"));
            var Retrospect = report.CreateChildPermission(AppPermissions.Pages_Report_Retrospects, L("Retrospects"));
            var Reports_UPH = report.CreateChildPermission(AppPermissions.Pages_Report_Reports_UPH, L("Retrospects"));
            var Reports_Report = report.CreateChildPermission(AppPermissions.Pages_Report_Reports_Report, L("Reports_Report"));
            var Reports_Offline = report.CreateChildPermission(AppPermissions.Pages_Report_Reports_Offline, L("Reports_Offline"));




            var aNDON = report.CreateChildPermission(AppPermissions.Pages_ANDON, L("ANDON"));
            aNDON.CreateChildPermission(AppPermissions.Pages_ANDON_CreateANDON, L("CreateANDON"));
            aNDON.CreateChildPermission(AppPermissions.Pages_ANDON_EditANDON, L("EditANDON"));
            aNDON.CreateChildPermission(AppPermissions.Pages_ANDON_DeleteANDON, L("DeleteANDON"));

            var stopEquipment = report.CreateChildPermission(AppPermissions.Pages_StopEquipment, L("ANDON"));
            stopEquipment.CreateChildPermission(AppPermissions.Pages_StopEquipment_CreateStopEquipment, L("CreateANDON"));
            stopEquipment.CreateChildPermission(AppPermissions.Pages_StopEquipment_EditStopEquipment, L("EditANDON"));
            stopEquipment.CreateChildPermission(AppPermissions.Pages_StopEquipment_DeleteStopEquipment, L("DeleteANDON"));


            //testSlides.CreateChildPermission(AppPermissions.Pages_Report_TestSlides_Create, L("CreatingNewTestSlide"));
            //testSlides.CreateChildPermission(AppPermissions.Pages_Report_TestSlides_Edit, L("EditingTestSlide"));
            //testSlides.CreateChildPermission(AppPermissions.Pages_Report_TestSlides_Delete, L("DeletingTestSlide"));



            //var alcCodeDetails = bom.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodeDetails, L("AlcCodeDetails"));
            //alcCodeDetails.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodeDetails_Create, L("CreatingNewAlcCodeDetail"));
            //alcCodeDetails.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodeDetails_Edit, L("EditingAlcCodeDetail"));
            //alcCodeDetails.CreateChildPermission(AppPermissions.Pages_Bom_AlcCodeDetails_Delete, L("DeletingAlcCodeDetail"));

            //users.CreateChildPermission(AppPermissions.Pages_Administration_Users_ChangePermissions, L("ChangingPermissions"));
            //users.CreateChildPermission(AppPermissions.Pages_Administration_Users_Impersonation, L("LoginForUsers"));

            //var languages = administration.CreateChildPermission(AppPermissions.Pages_Administration_Languages, L("Languages"));
            //languages.CreateChildPermission(AppPermissions.Pages_Administration_Languages_Create, L("CreatingNewLanguage"));
            //languages.CreateChildPermission(AppPermissions.Pages_Administration_Languages_Edit, L("EditingLanguage"));
            //languages.CreateChildPermission(AppPermissions.Pages_Administration_Languages_Delete, L("DeletingLanguages"));
            //languages.CreateChildPermission(AppPermissions.Pages_Administration_Languages_ChangeTexts, L("ChangingTexts"));

            //administration.CreateChildPermission(AppPermissions.Pages_Administration_AuditLogs, L("AuditLogs"));

            //var organizationUnits = administration.CreateChildPermission(AppPermissions.Pages_Administration_OrganizationUnits, L("OrganizationUnits"));
            //organizationUnits.CreateChildPermission(AppPermissions.Pages_Administration_OrganizationUnits_ManageOrganizationTree, L("ManagingOrganizationTree"));
            //organizationUnits.CreateChildPermission(AppPermissions.Pages_Administration_OrganizationUnits_ManageMembers, L("ManagingMembers"));


            ////Host permissions
            //var tenants = pages.CreateChildPermission(AppPermissions.Pages_Tenants, L("Tenants"), multiTenancySides: MultiTenancySides.Host);
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, MesConsts.LocalizationSourceName);
        }
    }
}
